'''
题：编写一个程序，根据控制台输入的事务日志计算银行帐户的净金额。 事务日志格式如下所示：
D 100
W 200
D表示存款，而W表示提款。
假设为程序提供了以下输入：
D 300
D 300
W 200
D 100
然后，输出应该是：
500
'''
#方法1：运用字典操作来实现(一次性的输入)
# operation_ = {}
# # l = input("输入:").split(" ")
# l = ['D', '300', 'D', '300', 'W', '200', 'D', '100']
# for i in range(0,len(l),2) :
#     if l[i] in operation_.keys():
#         operation_[l[i]]+=int(l[i+1])
#     else:
#         operation_.update({l[i]:int(l[i+1])})
# print(operation_)
# print(operation_["D"]-operation_["W"])
#更细致一点，就是需要加上判断{ch.isalpha}

#方法2:一次一次的输入
netAmount = 0
while True:
    print("请输入：")
    s = input()
    if not s:
        break
    values = s.split(" ")
    operation = values[0]
    amount = int(values[1])
    if operation=="D":
        netAmount+=amount
    elif operation=="W":
        netAmount-=amount
    else:
        pass
print (netAmount)


#方法3：使用类来实现并丰富这个功能
# class Amount:
#
#     def __init__(self):
#         self.D = 0
#         self.W = 0
#         self.freem = 0
#
#     def addD(self):
#         money = input("请输入存入金额:")
#         self.D += int(money)
#         print("%s存入:%s"%(self,money))
#
#     def addW(self):
#         money = input("请输入取出金额:")
#         self.W += int(money)
#         print("%s取出:%s" % (self, money))
#
#     def free(self):
#         self.freem = self.D - self.W
#         print("%s的余额:%d"%(self,self.freem))
#
#     def operation(self):
#         while True:
#              ch = input("是否继续操作(y/n)?")
#              if ch == "y":
#                  f = input("请输入操作D(存钱)W(取钱):")
#                  if f == "D":
#                      self.addD()
#                  else:
#                      self.addW()
#              else:
#                  break
#
#     def __str__(self):#对对象的描述，返回字符串描述
#         return "当前账户"
#
# a = Amount()
# f = input("请输入操作D(存钱)W(取钱):")
# if f == "D":
#     a.addD()
#     a.operation()
# elif f == "W":
#     a.addW()
#     a.operation()
# else:
#     print("操作指令不正确")
# a.free()

